from datetime import datetime
from fastapi import Query
from pydantic import BaseModel, Field

from app.utils.tool import to_lower_camel


class GoodsCateInSchema(BaseModel):
    name: str
    sort: int | None = Field(default=None, description="排序")
    status: int | None = Field(default=None, description="状态")
    remark: str | None = Field(default=None, description="备注")


class GoodsCateOutSchema(BaseModel):
    id: int = Field(None, description="ID")
    name: str
    sort: int | None = Field(default=None, description="排序")
    status: int | None = Field(default=None, description="状态")
    remark: str | None = Field(default=None, description="备注")

    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,

    }

    # class Config:
    #     from_attributes = True
    #     populate_by_name = True


class GoodsInSchema(BaseModel):
    cate_id: int | None = Field(default=None, description="排序", alias="cateId")
    name: str | None
    sort: int | None = Field(default=None, description="排序")
    status: int | None = Field(default=None, description="状态")
    remark: str | None = Field(default=None, description="备注")
    price: float | None


class GoodsDeleteInSchema(BaseModel):
    id: int = Field(description="商品ID")


class GoodsOutSchema(BaseModel):
    id: int | None
    cate_id: int | None = Field(
        default=None, description="分类id", alias="cateId")
    name: str | None
    sort: int | None
    status: int | None
    remark: str | None
    price: float | None

    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,
        "from_attributes": True,

    }
    # class Config:
    #     populate_by_name = True


class GoodsDetailInSchema(BaseModel):
    id: int = Query(gt=0, description="商品ID")
